import time

from selenium.webdriver.common.by import By

from com.yh.likeshop.base.page_object import PageObject
from com.yh.likeshop.base.test_parent import TestParent


class IndexPage(PageObject):

    searchEl = (By.XPATH,'//*[@id="__layout"]/div/header/div/div[2]/div/div/div/div/input')
    searchBl = (By.CLASS_NAME,'search-btn')
    resultDiv = (By.XPATH, '//*[@id="__layout"]/div/main/div/div[3]/div')


    def search(self,keyword):
        # 获取输入框元素
        self.send(*self.searchEl,content=keyword)

        # 点击搜索
        self.click(*self.searchBl)



    def checkSearch(self):
        try:
            time.sleep(1)
            el = self.findOne(*self.resultDiv)
            print(el.text)
        except Exception as e:  # 找到商品
                return True
        else:
                return False


